Skip to content

Conversation

@mattapperson
Copy link
Collaborator

@mattapperson mattapperson commented Dec 16, 2025

Summary

  • Adds support for Anthropic Claude-style messages (ClaudeMessageParam[]) as input to callModel()
  • Adds getClaudeMessage() output method returning Anthropic-compatible response format
  • Renames getMessage()getChatMessage() and getNewMessagesStream()getNewChatMessagesStream() for clarity

Input formats now supported:

  • OpenResponses format (native)
  • OpenAI Chat Completions format (Message[])
  • Anthropic Claude format (ClaudeMessageParam[])

New types added:

  • ClaudeMessage, ClaudeMessageParam, ClaudeContentBlock, and related types mirroring the Anthropic SDK

Add support for Anthropic Claude-style messages as input and output:

Input formats now supported:
- OpenResponses format (native)
- OpenAI Chat Completions format (Message[])
- Anthropic Claude format (ClaudeMessageParam[])

Output methods added/renamed:
- getChatMessage() - returns OpenAI chat format (renamed from getMessage)
- getClaudeMessage() - returns Anthropic Claude format (new)
- getNewChatMessagesStream() - stream chat messages (renamed from getNewMessagesStream)

Also includes:
- New ClaudeMessage types mirroring Anthropic SDK types
- Automatic format detection and conversion
- convertToClaudeMessage() helper for response transformation
- Updated examples demonstrating all input/output formats
- E2E tests for Claude-style message handling

BREAKING CHANGE: getMessage() renamed to getChatMessage()
BREAKING CHANGE: getNewMessagesStream() renamed to getNewChatMessagesStream()

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Copy link
Contributor

@louisgv louisgv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit weird to me in that we're shoving Anthropic input shape into callModel. Shouldn't we be owning the callModel API shape (?)

mattapperson and others added 8 commits December 16, 2025 15:20
Change return type from chat format (AssistantMessage | ToolResponseMessage)
to responses format (ResponsesOutputMessage | OpenResponsesFunctionCallOutput).

- Add buildResponsesMessageStream() for streaming ResponsesOutputMessage
- Add extractResponsesMessageFromResponse() for extracting from response
- Update tests to validate new ResponsesOutputMessage shape
- Update example and documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The getChatMessage method doesn't exist on ResponseWrapper.
Use getResponse() + toChatMessage() helper instead.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Demonstrates multi-turn conversations using:
- ClaudeMessageParam type for Claude-style message format
- fromClaudeMessages() to convert to OpenResponses input format
- toClaudeMessage() to convert responses back to Claude format

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The toChatMessage function is exported from chat-compat.js, not sdk.js.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@mattapperson mattapperson changed the title feat: add Anthropic Claude message format support to callModel feat: add Anthropic Claude message format helpers, fix some types and change names Dec 16, 2025
@mattapperson mattapperson requested a review from louisgv December 16, 2025 22:05
mattapperson and others added 4 commits December 16, 2025 17:08
The callModel function now accepts ClaudeMessageParam[] directly and
automatically converts them to OpenResponses format using fromClaudeMessages().

This enables passing Claude-style messages without manual conversion:
- ClaudeMessageParam[] with string content
- ClaudeMessageParam[] with content blocks (text, tool_use, tool_result, image)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add auto-detection of Claude-style messages with content block arrays
- Convert Claude content blocks (text, image) to OpenRouter format
- Fixes validation errors when passing Claude MessageParam directly to callModel()
- Resolves CI test failures for Claude-style messages with content blocks arrays
@mattapperson mattapperson merged commit a42a700 into main Dec 17, 2025
3 checks passed
@mattapperson mattapperson deleted the fix-types-and-anthropic-messages branch December 17, 2025 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants